<%@ page language="java" pageEncoding="us-ascii" contentType="text/html;charset=us-ascii" %>
<%--Copyright (C) 2011 Wolfgang Hankeln, Norma J. Wendel
	 
	This file is part of CDinFusion.
	
	CDinFusion is free software: you can redistribute it and/or
	modify it under the terms of the GNU Lesser General Public 
	License in version 3 (LGPL3) as published by the Free Software
	Foundation version 3 of the License.
	
	CDinFusion is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
	Lesser General Public License for more details.
	
	You should have received a copy of the Lesser General Public
	License along with CDinFusion; see the file COPYING. If not,
	write to the Free Software Foundation, 59 Temple Place - Suite 330,
	Boston, MA 02111-1307, USA or see <http://www.gnu.org/licenses/>.
	
	If you have any questions, send an email to: megx@mpi-bremen.de.
--%>
<%@ page import="org.cdinfusion.data.*"%>
<%@ page import="org.cdinfusion.data.studytype.*"%>
<%@ page import="org.cdinfusion.data.environment.*"%>
<%@ page import="java.util.ArrayList"%>
<%@ page import="java.util.List"%>
<%System.out.println("<<<<<<<<<<2b_GSC_SELECTED_nto_m>>>>>>>>>>");%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<link rel="stylesheet" type="text/css" href="css/style.css">
<style type="text/css">
</style>
<title> DIRECT CONTEXTUAL DATA INPUT n TO m</title> 
<jsp:include page="googleanalytics.jsp"/>

<script type="text/javascript">
function openpopup(url){
	fenster=window.open(url, "_blank", "width=600,height=400,status=yes, scrollbars=yes, resizable=yes, toolbar=1, menubar=1, location=1");
	fenster.focus();
	return false;
}
function select () {
var num = 1;
var mainresult = document.Formular.radio[0].checked;
/*study = none & env = none*/
result = document.Formular.StudyTypeDropDown.value.match("none") && document.Formular.EnvParamDropDown.value.match("none");
if(result){
  	num = -1;
}
if(num == -1 && mainresult){
	alert("Please select a type of report and a environmental package!");
    document.Formular.StudyTypeDropDown.focus();
    return false;
}
/*study = none*/
result = document.Formular.StudyTypeDropDown.value.match("none");
if(result){
  	num = -1;
}
if(num == -1 && mainresult){
	alert("Please select a type of report!");
    document.Formular.StudyTypeDropDown.focus();
    return false;
}
/*env = none*/
result = document.Formular.EnvParamDropDown.value.match("none");
if(result){
  	num = -1;
}
if(num == -1 && mainresult){
	alert("Please select a environmental package!");
    document.Formular.EnvParamDropDown.focus();
    return false;
}
//seq num > 10
var seq_num = document.Formular.seq_num.value;
var result = document.Formular.radio[1].checked;
if(result  && seq_num > 10){
	var answer = confirm ("Are you sure, that you want to enter contextual data for each sequence ID?")
	if (answer)
	return true;
	else
	return false;
}
}/*end function*/
</script>
</head>

<body>
<table border="0" width="100%" bgcolor="#2B3990" cellpadding=0 cellspacing=0>
<tr bgcolor="#ffffff">
<td width=250>
<center>
<img height="81" width="250" alt="CDinFusion Logo" src="/CDinFusion/img/logo_small_dark.png">
</center>
</td>
</tr>

<tr align="left">    
<td>
<jsp:include page="documentation/navigation.jsp"></jsp:include>
</td>
</tr>

<%
String sessionID = session.getId();
String origin = (String) session.getAttribute("origin");
String context_exists = "no";
String opt_2b = "";
List<String> seqIDs = (List<String>) session.getAttribute("allSequenceIDs");
Integer numberOfSequencesUploaded = (Integer)session.getAttribute("numberOfSequencesUploaded");
int id_num = 10;
String studytype = "";
String envtype = "";

//where did you come from?
if(origin.contains("2b_csv")){
	opt_2b = (String) session.getAttribute("opt_2b");
	context_exists = (String)session.getAttribute("context_exists");
	List<CDElement> cdeLIST = (List<CDElement>) session.getAttribute("cdeLIST");
	studytype = cdeLIST.get(0).getStudy().getClass().toString().toLowerCase().substring(36);
	envtype = cdeLIST.get(0).getEnv().getClass().toString().toLowerCase().substring(38);
}
if(origin.contains("5")){
	opt_2b = (String) session.getAttribute("opt_2b");
	context_exists = (String) session.getAttribute("context_exists");//yes
	List<CDElement> oldLIST = (List<CDElement>) session.getAttribute("cdeLIST");
	if(oldLIST.size() == 1){
		studytype = oldLIST.get(0).getStudy().getClass().toString().toLowerCase().substring(36).trim();
		envtype = oldLIST.get(0).getEnv().getClass().toString().toLowerCase().substring(38).trim();
		session.setAttribute("oldLIST", oldLIST);
	}	
}
session.setAttribute("context_exists", context_exists);
%>

<tr bgcolor="#ffffff">
<td>
<div class="center_div">    
<br>
<center><b> Specify GSC compliant contextual data:</b> <a href="gsc_package_info.htm?item=general" target="_blank" onclick="openpopup(this.href); return false"> more info </a> <br>
Chose type of report and environmental package: <br>
</center>
<%
if(numberOfSequencesUploaded <= id_num){%>
	<center><p> The FASTA file contains <strong><%=numberOfSequencesUploaded%></strong> sequence IDs:</p>
	<ul style="list-style-type:disc; margin-left: 220;"><%
		for(int i = 0; i < seqIDs.size(); i ++){
			%>
			<li><%=seqIDs.get(i)%></li>
			<%
		}%>
	</ul>
	</center>
<%}else{%>
	<center><p> The FASTA file contains <strong><%=numberOfSequencesUploaded%></strong> sequence IDs, they start with <br>
	the ID <strong><%=seqIDs.get(0)%></strong> and end with <strong><%=seqIDs.get(seqIDs.size()-1)%></strong>.
	</p></center>
<%}%>

<form name="Formular" action="GSC_choice_b.htm" method="post" onsubmit="return select ()">
	<%if(opt_2b.equals("one")|origin.contains("uploadfasta_many")){%>	
		<p style="margin-left: 120px;"><input type="radio" name="radio" value="one cd set for all" checked>one contextual data set for all sequences</p>
	<%}
	if(opt_2b.equals("many")){%>
		<p style="margin-left: 120px;"><input type="radio" name="radio" value="one cd set for all">one contextual data set for all sequences</p>
	<%}%>
	<p style="margin-left: 220px;"> 
	type of report:
	<select name="StudyTypeDropDown" size="1"> 
			<option value="none">none selected</option>
		<%
		if(studytype.equals("mimarks_s")){%>
			<option selected value="mimarks_s">MIMARKS survey (mimarks_s)</option>
		<%}
		else{%>
			<option value="mimarks_s">MIMARKS survey (mimarks_s)</option>
		<%}
		if(studytype.equals("mimarks_c")){%>
			<option selected value="mimarks_c">MIMARKS culture (mimarks_c)</option>
		<%}
		else{%>
			<option value="mimarks_c">MIMARKS culture (mimarks_c)</option>
		<%}
		if(studytype.equals("eu")){%>
			<option selected value="eu">MIGS eukaryotes (eu)</option>
		<%}
		else{%>
			<option value="eu">MIGS eukaryotes (eu)</option>
		<%}
		if(studytype.equals("ba")){%>
			<option selected value="ba">MIGS bacteria and archaea (ba)</option>
		<%}
		else{%>
			<option value="ba">MIGS bacteria and archaea (ba)</option>  
		<%}
		if(studytype.equals("pl")){%>
			<option selected value="pl">MIGS plasmid (pl)</option>
		<%}
		else{%>
			<option value="pl">MIGS plasmid (pl)</option>
		<%}
		if(studytype.equals("vi")){%>
			<option selected value="vi">MIGS virus (vi)</option>
		<%}
		else{%>
			<option value="vi">MIGS virus (vi)</option>
		<%}
		if(studytype.equals("org")){%>
			<option selected value="org">MIGS organelle (org)</option>
		<%}
    	else{%>
    		<option value="org">MIGS organelle (org)</option>
    	<%}
    	if(studytype.equals("me")){%>
    		<option selected value="me">MIMS metagenome (me)</option>
    	<%}
    	else{%>
    		<option value="me">MIMS metagenome (me)</option>
    	<%}%>
    </select>
	<a href="gsc_package_info.htm?item=typeofreport" target="_blank" onclick="openpopup(this.href); return false"> more info </a></p>
	<p style="margin-left: 220px;">
	environmental package:
	<select name="EnvParamDropDown" size="1"> 
    		<option value="none">none selected</option>
		<%
	 	if(envtype.equals("water")){%>
			<option selected value="water">water</option>
		<%}
		else{%>
			<option value="water">water</option>
		<%}
		if(envtype.equals("wastewater")){%>
			<option selected value="wastewater">wastewater/sludge</option>
		<%}
		else{%>
			<option value="wastewater">wastewater/sludge</option>
		<%}
		if(envtype.equals("soil")){%>
			<option selected value="soil">soil</option>
		<%}
		else{%>
			<option value="soil">soil</option>
		<%}
		if(envtype.equals("sediment")){%>
			<option selected value="sediment">sediment</option>
		<%}
		else{%>
			<option value="sediment">sediment</option>
		<%}
		if(envtype.equals("plant_associated")){%>
			<option selected value="plant_associated">plant-associated</option>
		<%}
		else{%>
			<option value="plant_associated">plant-associated</option>
		<%}
		if(envtype.equals("miscellaneous")){%>
			<option selected value="miscellaneous">miscellaneous</option>
		<%}
		else{%>
			<option value="miscellaneous">miscellaneous</option>
		<%}
		if(envtype.equals("biofilm")){%>
			<option selected value="biofilm">microbial mat/biofilm</option>
		<%}
		else{%>
			<option value="biofilm">microbial mat/biofilm</option>
		<%}
		if(envtype.equals("human_vaginal")){%>
			<option selected value="human_vaginal">human-vaginal</option>
		<%}
		else{%>
			<option value="human_vaginal">human-vaginal</option>
		<%}
		if(envtype.equals("human_skin")){%>
			<option selected value="human_skin">human-skin</option>
		<%}
		else{%>
			<option value="human_skin">human-skin</option>
		<%}
		if(envtype.equals("human_oral")){%>
			<option selected value="human_oral">human-oral</option>
		<%}
		else{%>
			<option value="human_oral">human-oral</option>
		<%}
		if(envtype.equals("human_gut")){%>
			<option selected value="human_gut">human-gut</option>
		<%}
		else{%>
			<option value="human_gut">human-gut</option>
		<%}
		if(envtype.equals("human_associated")){%>
			<option selected value="human_associated">human-associated</option>
		<%}
		else{%>
			<option value="human_associated">human-associated</option>
		<%}
		if(envtype.equals("host_associated")){%>
			<option selected value="host_associated">host-associated</option>
		<%}
		else{%>
			<option value="host_associated">host-associated</option>
		<%}
		if(envtype.equals("air")){%>
			<option selected value="air">air</option>
		<%}
		else{%>
			<option value="air">air</option>
		<%}%>
	</select>
	<a href="gsc_package_info.htm?item=environmentalpackage" target="_blank" onclick="openpopup(this.href); return false"> more info </a></p>
	<p style="margin-left: 220px;"> current selection as empty spreadsheet template <input class="submitbutton" type="submit" name="submit" value="download empty csv"></p>
	
	<%if (numberOfSequencesUploaded <= 1000) {%>
		<%if(opt_2b.equals("many")){ %>
			<p style="margin-left: 120px;"><input type="radio" name="radio" value="many cd sets for many" checked>many contextual data sets for selected subsets of sequences</p>
		<%}else{ %>
			<p style="margin-left: 120px;"><input type="radio" name="radio" value="many cd sets for many">many contextual data sets for selected subsets of sequences</p>
		<%}%>
	<%} %>		
	<%session.setAttribute("origin", "2b");%>
	<input type="hidden" name="seq_num" value="<%=seqIDs.size()%>">
	<center><input class="submitbutton" type="submit" name="submit" value="proceed"></center>
</form>

</div>
</td>
</tr>
<tr bgcolor="#ffffff"><td align="right" height=30>
	<img height="20" width="200" alt="CDinFusion Step 2" src="/CDinFusion/img/step2.png">
</td></tr>
<jsp:include page="documentation/bottom_info.jsp"></jsp:include>
</table>
</body>
</html>